{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1591287e",
   "metadata": {},
   "source": [
    "* 十五周"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "04590362",
   "metadata": {},
   "source": [
    "# 本周知识\n",
    ">1.函数的返回值\n",
    ">2.函数的输入参数类型\n",
    ">3.函数的返回参数类型\n",
    ">4.模块的概念\n",
    ">5.如何创建一个模块"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4aa34392",
   "metadata": {},
   "source": [
    ">1.函数的返回值 \n",
    ">>关键字 return\n",
    ">>其他语音必须写 python会报none\n",
    ">>返回值一般表现为函数的运行结果 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "96cc418b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 函数的返回值\n",
    "def get_formatted_name(first_name,last_name):\n",
    "    full_name = first_name +' '+last_name\n",
    "    return full_name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6c55c603",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'li hua'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "get_formatted_name(\"li\",\"hua\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "0346ee1a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "lihua\n"
     ]
    }
   ],
   "source": [
    "print(get_formatted_name(\"li\",\"hua\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "948351c2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 函数返回值实践2\n",
    "def log_in(username,password):\n",
    "    \"\"\"验证登录信息\"\"\"\n",
    "    if username == \"Lihua\" and password == 123456:\n",
    "        return 1\n",
    "    else:\n",
    "        return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "dd7e86fe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_in(\"wy\",123456)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "20c98d2b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_in(\"Lihua\",123456)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "17c0da85",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_in(\"lihua\",\"123456\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "a6c9294b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 函数返回值实践2\n",
    "def log_in1(username,password):\n",
    "    if username in uesr_name_list:\n",
    "        if password == password:\n",
    "            return 0\n",
    "        else:\n",
    "            return 1\n",
    "    else:\n",
    "        return 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "dbe4bb0e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "log_in1(\"ll\",\"123456\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5487eb00",
   "metadata": {},
   "source": [
    "# 参数输入\n",
    "## 1.函数在使用过程中可以输入复杂的参数 例如列表 字典 集合 元组\n",
    "### a.为列表\n",
    "### b.为字典\n",
    "# ....\n",
    "## 2.函数可以输入不确定的个数：\n",
    "### a.*args 多个单数据\n",
    "### b.**kwargs  可以对应key\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "6b308149",
   "metadata": {},
   "outputs": [],
   "source": [
    "def test_a(names):\n",
    "    '''为列表'''\n",
    "    return names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "132066df",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['11', '22', '33']"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_a([\"11\",\"22\",\"33\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "49342e99",
   "metadata": {},
   "outputs": [],
   "source": [
    "def test_b(person):\n",
    "    return person"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "43768c67",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stuid': 2011, 'age': 15, 'job': 'student'}"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_b({\"stuid\":2011,\"age\":15,\"job\":\"student\"})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "b885bcab",
   "metadata": {},
   "outputs": [],
   "source": [
    "def food_ingreds(food,*ingreds):\n",
    "    return food,ingreds\n",
    "# *放列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "cbc4062f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('pizza', ('apple', 'coffe', 'milk'))"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "food_ingreds(\"pizza\",\"apple\",\"coffe\",\"milk\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "dbfef972",
   "metadata": {},
   "outputs": [],
   "source": [
    "def person(stu_name,**stu_course):\n",
    "    return stu_name,stu_course\n",
    "# **可以放字典\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "bcebbbc4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('lihua', {'course_1': 'api', 'course_2': 'pyhton'})"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "person(\"lihua\",course_1=\"api\",course_2=\"pyhton\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "184426c5",
   "metadata": {},
   "source": [
    "# 函数的输出 （返回值） 参数类型\n",
    "## 1.只能是是一个值\n",
    "## 2.返回值可以是 字符串 数值 列表 字典等数据 （单一值\n",
    "## 3.python可以输出多个返回值，结果会用一个元组进行封装并返回。（本质不违背函数的定义）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "142b22a6",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "23251c99",
   "metadata": {},
   "outputs": [],
   "source": [
    "def test1_return():\n",
    "    return 12345"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "021c2567",
   "metadata": {},
   "outputs": [],
   "source": [
    "def test2_return():\n",
    "    return \"你好\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b3efe648",
   "metadata": {},
   "outputs": [],
   "source": [
    "def test3_return():\n",
    "    return['lihua','qqq','www']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d9f978ea",
   "metadata": {},
   "outputs": [],
   "source": [
    "def test4_return():\n",
    "    return {\"stuid\":2011,\"age\":15,\"job\":\"student\"}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "2d513247",
   "metadata": {},
   "outputs": [],
   "source": [
    "# **********\n",
    "def test5_return():\n",
    "    return 18,\"qqqq\",['lihua','qqq','www'],{\"stuid\":2011,\"age\":15,\"job\":\"student\"}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "067b28b9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(18,\n",
       " 'qqqq',\n",
       " ['lihua', 'qqq', 'www'],\n",
       " {'stuid': 2011, 'age': 15, 'job': 'student'})"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test5_return()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7696cb2f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'你好'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test2_return()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "12db721e",
   "metadata": {},
   "outputs": [],
   "source": [
    "def test1_return():\n",
    "    return 12345"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3e4c70ec",
   "metadata": {},
   "source": [
    "---------\n",
    "# 模块\n",
    "## 1.函数的源代码在使用时可以被隐藏\n",
    "## 2.使用的人不需要懂底层代码\n",
    "## 3.模块的使用方式 import time\n",
    "### 使用 模块名.函数名()\n",
    "### 使用 函数名  form模块名 import函数名"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "4c24a219",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "0e9de8a6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2021, tm_mon=12, tm_mday=22, tm_hour=20, tm_min=40, tm_sec=14, tm_wday=2, tm_yday=356, tm_isdst=0)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "da9b3534",
   "metadata": {},
   "outputs": [],
   "source": [
    "from time import localtime\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "55884237",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2021, tm_mon=12, tm_mday=22, tm_hour=20, tm_min=40, tm_sec=14, tm_wday=2, tm_yday=356, tm_isdst=0)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "2ead01be",
   "metadata": {},
   "outputs": [],
   "source": [
    "import study"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "96690d8e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'a', 'e', 'i', 'o'}"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 函数的调用\n",
    "study.search4vowels(\"hello zhichao\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2d1e08ed",
   "metadata": {},
   "source": [
    "help(study.news_链接)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "851f3f00",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['https://www.nfu.edu.cn/xydt/index.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index1.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index2.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index3.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index4.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index5.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index6.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index7.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index8.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index9.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index10.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index11.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index12.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index13.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index14.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index15.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index16.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index17.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index18.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index19.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index20.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index21.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index22.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index23.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index24.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index25.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index26.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index27.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index28.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index29.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index30.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index31.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index32.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index33.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index34.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index35.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index36.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index37.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index38.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index39.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index40.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index41.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index42.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index43.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index44.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index45.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index46.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index47.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index48.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index49.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index50.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index51.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index52.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index53.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index54.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index55.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index56.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index57.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index58.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index59.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index60.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index61.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index62.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index63.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index64.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index65.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index66.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index67.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index68.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index69.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index70.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index71.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index72.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index73.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index74.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index75.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index76.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index77.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index78.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index79.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index80.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index81.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index82.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index83.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index84.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index85.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index86.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index87.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index88.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index89.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index90.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index91.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index92.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index93.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index94.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index95.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index96.htm',\n",
       " 'https://www.nfu.edu.cn/xydt/index97.htm']"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "study.news_链接('https://www.nfu.edu.cn/','xydt','98')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
